<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page import ="java.sql.*"%>

<%
request.setCharacterEncoding("utf-8");
String name = request.getParameter("name");
String address = request.getParameter("address");
String telephone = request.getParameter("telephone");
int age = Integer.parseInt(request.getParameter("age"));
String gender = request.getParameter("gender");
int no = Integer.parseInt(request.getParameter("no"));

Class.forName("com.mysql.jdbc.Driver");

Connection conn =null;
PreparedStatement stmt = null;
ResultSet rs = null;

try{
        String url = "jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=utf8";
        String username = "root";
        String password = "6473";
        conn = DriverManager.getConnection(url, username, password);

         String sql = "update namecard set name=?,address=?,telephone=?,age=?,gender=? where id=?;";
         stmt = conn.prepareStatement(sql);
         stmt.setString(1, name);
         stmt.setString(2, address);
         stmt.setString(3, telephone);
         stmt.setInt(4, age);
         stmt.setString(5, gender);
         stmt.setInt(6,no);

         stmt.executeUpdate();

}finally{
        if(stmt!=null)
                try{stmt.close();}catch(SQLException ex){}
        if(conn!=null)
                try{conn.close();}catch(SQLException ex){}
}
%>

